import {Component} from '@angular/core'
import {User} from './user.model'
import {UserServcie} from './user.service'
@Component({
	moduleId:module.id,
	selector:"user-list",
	templateUrl:'user-list.component.html'

})
export class UserListComponent{
	users:User[];
	currentUser:User;
	constructor(private userService:UserServcie){
		userService.findAllUsers()
		.subscribe(us=>this.users=us);
	}
	deleteUser(id:string):void{
		this.userService.deleteUser(id)
		.subscribe(u=>{
			this.users=this.users.filter(x=>x.id!=id);
		})
	}
	addUser(name:string,age:number):void{
		this.userService.addUser(name,age)
		.subscribe(u=>this.users.push(u));
	}
	selectUser(user:User):void{
		this.currentUser=user;
	}
	updateUser(user:User):void{
		this.userService.updateUser(user)
		.subscribe(u=>{});
	}
}





